package com.ruanyun.modular.admin.controller;

import com.ruanyun.base.pojo.page.LayuiPageInfo;
import com.ruanyun.modular.admin.entity.TMeasures;
import com.ruanyun.modular.admin.model.params.TMeasuresParam;
import com.ruanyun.modular.admin.service.TMeasuresService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 措施信息控制器
 *
 * @author zs
 * @Date 2021-05-11 19:04:36
 */
@Controller
@RequestMapping("/tMeasures")
public class TMeasuresController extends BaseController {

    private String PREFIX = "/vocReducingPlan";

    @Autowired
    private TMeasuresService tMeasuresService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/tMeasures.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/tMeasures_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/tMeasures_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TMeasuresParam tMeasuresParam) {
        return this.tMeasuresService.add(tMeasuresParam);
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TMeasuresParam tMeasuresParam) {
        return this.tMeasuresService.update(tMeasuresParam);
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TMeasuresParam tMeasuresParam) {
        return this.tMeasuresService.updateDelFlagById((long)tMeasuresParam.getId());
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2021-05-11
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TMeasuresParam tMeasuresParam) {
        TMeasures detail = this.tMeasuresService.getById(tMeasuresParam.getId());
        return ResponseData.success(detail);
    }


    /**
     * 启用
     *
     * @author zs
     * @Date 2021-05-11
     */
    @ResponseBody
    @RequestMapping("/enable")
    public ResponseData enable(@RequestParam Long id) {
        return this.tMeasuresService.enableById(id);
    }

    /**
     * 禁用
     *
     * @author zs
     * @Date 2021-05-11
     */
    @ResponseBody
    @RequestMapping("/disable")
    public ResponseData disable(@RequestParam Long id) {
        return this.tMeasuresService.disableById(id);
    }


    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-05-11
     */
    @ResponseBody
    @RequestMapping("/measureInfo")
    public LayuiPageInfo measureInfo(Integer companyId) {
        return this.tMeasuresService.measureInfo(companyId);
    }



    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-05-11
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(Integer redId,Integer redType,Integer measureType) {
        return this.tMeasuresService.findPageBySpec(redId,redType,measureType);
    }



    /**
     * 查询减排合计
     *
     * @author zs
     * @Date 2021-05-11
     */
    @ResponseBody
    @RequestMapping("/measureHeadInfo")
    public ResponseData measureHeadInfo(Integer companyId) {
        return  ResponseData.success(this.tMeasuresService.measureHeadInfo(companyId));
    }
}


